From aec45be72159d19fc504cf052db8efbecefe9f4f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 20 Mar 2014 15:17:19 -0700 Subject: [PATCH] Cleanup integration test --- libs/hamcrest-rust | 2 +- src/cargo/util/mod.rs | 2 +- tests/support.rs | 30 ++++++++++++++++++++++++++-- tests/test_cargo_compile.rs | 39 +++---------------------------------- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/libs/hamcrest-rust b/libs/hamcrest-rust index 39f006244..4c7d88245 160000 --- a/libs/hamcrest-rust +++ b/libs/hamcrest-rust @@ -1 +1 @@ -Subproject commit 39f00624492fd648631041eadf1301a08cd2a482 +Subproject commit 4c7d8824550299dbddf2671515cba05f8d1a1fb2 diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index 27784a1ec..e4fbd2514 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -1,2 +1,2 @@ -pub use self::process_builder::process; +pub use self::process_builder::{process,ProcessBuilder}; pub mod process_builder; diff --git a/tests/support.rs b/tests/support.rs index 0c5242dff..dfe349774 100644 --- a/tests/support.rs +++ b/tests/support.rs @@ -1,11 +1,18 @@ // use std::io::fs::{mkdir_recursive,rmdir_recursive}; use std::io::fs; -use std::os::tmpdir; +use std::os; use std::path::{Path}; +use cargo::util::{process,ProcessBuilder}; static CARGO_INTEGRATION_TEST_DIR : &'static str = "cargo-integration-tests"; static MKDIR_PERM : u32 = 0o755; +/* + * + * ===== Builders ===== + * + */ + #[deriving(Eq,Clone)] struct FileBuilder { path: Path, @@ -53,6 +60,12 @@ impl ProjectBuilder { self.root.clone() } + pub fn cargo_process(&self, program: &str) -> ProcessBuilder { + process(program) + .cwd(self.root()) + .extra_path(cargo_dir()) + } + pub fn file(mut self, path: &str, body: &str) -> ProjectBuilder { self.files.push(FileBuilder::new(self.root.join(path), body)); self @@ -94,7 +107,7 @@ impl ProjectBuilder { // Generates a project layout pub fn project(name: &str) -> ProjectBuilder { - ProjectBuilder::new(name, tmpdir().join(CARGO_INTEGRATION_TEST_DIR)) + ProjectBuilder::new(name, os::tmpdir().join(CARGO_INTEGRATION_TEST_DIR)) } // === Helpers === @@ -121,3 +134,16 @@ impl ErrMsg for Result { } } } + +// Path to cargo executables +pub fn cargo_dir() -> ~str { + os::getenv("CARGO_BIN_PATH").unwrap_or_else(|| { + fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test") + }) +} + +/* + * + * ===== Matchers ===== + * + */ diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 3cdc5630d..c4769bd32 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1,33 +1,9 @@ use std; use support::project; -use hamcrest::{SelfDescribing,Description,Matcher,assert_that}; +use hamcrest::{assert_that,existing_file}; use cargo; -#[deriving(Clone,Eq)] -pub struct ExistingFile; - -impl SelfDescribing for ExistingFile { - fn describe_to(&self, desc: &mut Description) { - desc.append_text("an existing file"); - } -} - -impl Matcher for ExistingFile { - fn matches(&self, actual: &Path) -> bool { - actual.exists() - } - - fn describe_mismatch(&self, actual: &Path, desc: &mut Description) { - desc.append_text(format!("`{}` was missing", actual.display())); - } -} - -pub fn existing_file() -> ExistingFile { - ExistingFile -} - fn setup() { - } test!(cargo_compile_with_explicit_manifest_path { @@ -49,10 +25,8 @@ test!(cargo_compile_with_explicit_manifest_path { }"#) .build(); - let output = cargo::util::process("cargo-compile") + let output = p.cargo_process("cargo-compile") .args([~"--manifest-path", ~"Cargo.toml"]) - .extra_path(target_path()) - .cwd(p.root()) .exec_with_output(); match output { @@ -63,8 +37,7 @@ test!(cargo_compile_with_explicit_manifest_path { Err(e) => println!("err: {}", e) } - assert_that(p.root().join("target/foo/bar"), existing_file()); - assert!(p.root().join("target/foo").exists(), "the executable exists"); + assert_that(&p.root().join("target/foo"), existing_file()); let o = cargo::util::process("foo") .extra_path(format!("{}", p.root().join("target").display())) @@ -75,9 +48,3 @@ test!(cargo_compile_with_explicit_manifest_path { }) // test!(compiling_project_with_invalid_manifest) - -fn target_path() -> ~str { - std::os::getenv("CARGO_BIN_PATH").unwrap_or_else(|| { - fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test") - }) -} -- 2.30.2